package com.example.demo.controller;

import Mapper.TipMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController

public class TipController {

    @Autowired
    private TipMapper tipMapper;

    @GetMapping("/gettip")
    public String getTip() {
        int total = tipMapper.getTotal(); // 获取总条数
        System.out.println(total);
        Random random = new Random();
        int num = random.nextInt(total) + 1; // 确保 num 在 1 到 total 之间
        String text = tipMapper.getTip(num); // 根据随机数获取 tip 数据
        System.out.println(text);
        return text;
    }

}
